<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加更新</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
  <style>
    @media screen and (min-width: 490px) {
      .layui-form-item .layui-input-inline {
        width: 70%;
      }
    }
  </style>
</head>
<body>
<form enctype="multipart/form-data" id="up_form">
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">版本号</label>
    <div class="layui-input-inline">
      <input type="text" name="uVersion" lay-verify="required" placeholder="请输入版本号" maxlength="8" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">更新说明</label>
    <div class="layui-input-inline">
      <textarea type="text" name="uContent" lay-verify="required" style="height: 100px;padding: 8px;" maxlength="255" placeholder="请输入更新说明" autocomplete="off" class="layui-input"></textarea>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">安装包</label>
    <div class="layui-input-inline" id="choosefile">
      <button type="button" class="layui-btn layui-btn-danger" id="choosefile_input">
        <i class="layui-icon">&#xe67c;</i>请选择附件
      </button>
      <span style="color: red;margin-left: 5px;">* 支持apk格式文件上传</span>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">最低版本</label>
    <div class="layui-input-inline">
      <input type="text" name="uLimit" lay-verify="" placeholder="请输入最低版本" value="1.0" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item layui-hide">
    <input type="button" lay-submit lay-filter="LAY-front-submit" id="LAY-front-submit" value="确认">
  </div>
</div>
</form>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,upload = layui.upload ;

        layui.upload.render({
            elem: '#choosefile_input',
            url: '',
            accept: 'file',
            exts: 'apk',
            auto: false, //选择文件后不自动上传
            size:102400,
            // bindAction: '#testListAction', //指向一个按钮触发上传
        });

        form.on("submit(LAY-front-submit)",function(obj){
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            var formSatellite = document.getElementById("up_form");//获取所要提交form的id
            var fs1 = new FormData(formSatellite);  //用所要提交form做参数建立一个formdata对象
            console.log(obj.field);
            console.log(fs1);
            $.ajax({
                url:"addUpdate",
                dataType:"json",
                type:"post",
                data:fs1,
                async : true,
                contentType: false,   //ajax 中 contentType 设置为 false 是为了避免 JQuery 对其操作，从而失去分界符，而使服务器不能正常解析文件
                processData: false,   //当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                success:function(result){
                    top.layer.close(index);
                    if(result.status=="1") {
                        top.layer.msg("发布成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();//href='homework?coId='+obj.data.coId;
                    }
                    else if(result.status=="0") {
                        top.layer.msg("发布失败！");
                    }
                    else{
                        layer.msg(result.tips, {
                            time: 3000
                            ,icon:2
                            ,anim:6
                        });
                    }
                },
                error:function(result){
                    top.layer.close(index);
                    console.log(result);
                    alert("系统繁忙！");
                }
            });
            return false;
        })

    })
</script>
</body>
</html>